package com.tools.module.base.web;

import com.tools.common.config.AbstractController;
import com.tools.common.model.Result;
import com.tools.common.util.DateUtils;
import com.tools.common.util.ShiroUtils;
import com.tools.module.base.entity.BaseGroup;
import com.tools.module.base.service.BaseGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/base/group")
public class BaseGroupController extends AbstractController {

    @Autowired
    private BaseGroupService groupService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public Result list(BaseGroup group){
        return groupService.list(group);
    }
    /**
     * 查询
     */
    @PostMapping("/get")
    public Result get(Long id){
        return groupService.get(id);
    }
    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody BaseGroup group){
        if (group.getId()==null){
            group.setCreateTime(DateUtils.getTimestamp());
            group.setCreateUid(ShiroUtils.getUserId());
        }
        group.setUpdateUid(ShiroUtils.getUserId());
        Long aLong = groupService.queryBySeq(group);
        if (aLong>0) {
            groupService.updateSeq(group);
        };
        return groupService.save(group);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(Long id){
        return groupService.delete(id);
    }

    /**
     * 列表
     */
    @PostMapping("/queryPeopleByGroupId")
    public Result queryPeopleByGroupId(BaseGroup group){
        return groupService.queryPeopleByGroupId(group);
    }
}
